import pygame
import random
import EnemyStar


class Enemy:
    # initialize parameters
    # kind: enemy kind
    # set_pos_x,set_pos_y: enemy initial corrdinate
    def __init__(self, kind, set_pos_x, set_pos_y):
        # configuration
        self.kind = kind  # kind
        self.state = False  # if enemy is dead

        # Mummy
        if self.kind == 1:
            # load image resource
            self.enemy_image_left = pygame.image.load(r"image/enemy_1_left.png").convert_alpha()
            self.enemy_image_right = pygame.image.load(r"image/enemy_1_right.png").convert_alpha()
            self.enemy_image_dead = pygame.image.load(r"image/really_dead_mummy.png").convert_alpha()

            self.HP = 50  # initial HP
            self.boom_time = 50
            self.init_HP = 50
            # initial coordinate
            self.coord_x = set_pos_x
            self.coord_y = set_pos_y
            # enemy speed
            self.enemy_speed = 1
            self.path = tuple()  # shortest path to Laura

        # Skeleton guard
        elif self.kind == 2:
            # load image resource
            self.enemy_image_left = pygame.image.load(r"image/enemy_2_left.png").convert_alpha()
            self.enemy_image_right = pygame.image.load(r"image/enemy_2_right.png").convert_alpha()
            self.enemy_image_dead = pygame.image.load(r"image/dead_guard.png").convert_alpha()

            self.HP = 100  # initialize HP
            self.boom_time = 50
            self.init_HP = 100
            # initial coordinate
            self.coord_x = set_pos_x
            self.coord_y = set_pos_y

            self.enemy_speed = 1  # enemy speed
            self.path = tuple()  # shortest path to Laura

            # frame-based period for spell generation
            self.fire_time = 100
            # skeleton's remaining spell
            self.remain_star = 10

        # 法老
        elif self.kind == 3:
            # load image resource
            self.enemy_image = pygame.image.load(r"image/enemy_3.png").convert_alpha()
            self.enemy_image_dead = pygame.image.load(r"image/really_dead_Pharaoh.png").convert_alpha()
            self.HP = 1000  # initial HP
            self.fire_time = 100
            self.boom_time = 20
            self.init_HP = 400
            self.summon = True
            # initial coordinate
            self.coord_x = set_pos_x
            self.coord_y = set_pos_y
            self.enemy_speed = 0  # enemy speed
            self.path = tuple()  # shortest path to Laura

    # damage function
    # shift state if HP is less than or equal to 0
    def damage_enemy(self, mag):
        self.HP -= mag
        if self.HP <= 0:
            self.HP = 0
            self.state = True

    # judge if enemy is dead and shift state
    def death_(self):
        if self.state:
            if self.kind == 1:
                self.enemy_speed = 0
                sound = pygame.mixer.Sound("sound/sound_effect/enemy_dead.wav")
                sound.set_volume(0.5)
                sound.play()
            elif self.kind == 2:
                self.enemy_speed = 0
                sound = pygame.mixer.Sound("sound/sound_effect/enemy_dead.wav")
                sound.set_volume(0.5)
                sound.play()
            elif self.kind == 3:
                sound = pygame.mixer.Sound("sound/sound_effect/enemy_dead.wav")
                sound.set_volume(0.5)
                sound.play()
